package com.google.code.sip.ucenter.imports;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.code.sip.ucenter.dao.mongo.SettingDaoImpl;
import com.google.code.sip.ucenter.model.Setting;

@Service("settingImporter")
public class SettingImporter extends AbstractImporter<Setting> {
	@Autowired
	private SettingDaoImpl settingDao;

	@Override
	protected Setting toEntity(Map<String, String> props) {
		Setting setting = new Setting();
		for (Map.Entry<String, String> entry : props.entrySet()) {
			String name = entry.getKey();
			String value = entry.getValue();
			try {
				if (entityClass.getDeclaredField(name) != null) {
					beanUtilsBean.copyProperty(setting, name, value);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return setting;
	}

	@Override
	protected void doSave(Setting setting) {
		settingDao.save(setting);
	}

	@Override
	protected void doInit() {
		settingDao.clear();
	}

}
